﻿(function () {
    function initAppBar() {
        var appBarDiv = document.getElementById("scenarioAppBar");
        var appBar = document.getElementById("scenarioAppBar").winControl;
        // Add event listeners
        document.getElementById("cmdAdd").addEventListener("click", doClickAdd, false);
        document.getElementById("cmdDelete").addEventListener("click", doClickDelete, false);
        document.getElementById("cmdSelectAll").addEventListener("click", doClickSelectAll, false);
        document.getElementById("cmdClearSelection").addEventListener("click", doClickClearSelection, false);
        appBar.addEventListener("beforeshow", doAppBarShow, false);
        appBar.addEventListener("beforehide", doAppBarHide, false);
        // Hide selection group of commands
        appBar.hideCommands(appBarDiv.querySelectorAll('.multiSelect'));
        // Disable AppBar until in full screen mode
        appBar.disabled = true;
    }

    function doSelectItem() {
        var appBarDiv = document.getElementById("scenarioAppBar");
        var appBar = document.getElementById('scenarioAppBar').winControl;
        var listView = document.getElementById("scenarioListView").winControl;
        var count = listView.selection.count();
        if (count > 0) {
            // Show selection commands in AppBar
            appBar.showCommands(appBarDiv.querySelectorAll('.multiSelect'));
            appBar.sticky = true;
            appBar.show();
        } else {
            // Hide selection commands in AppBar
            appBar.hide();
            appBar.hideCommands(appBarDiv.querySelectorAll('.multiSelect'));
            appBar.sticky = false;
        }
    }
}());